/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.com.switz.dao.Impl;

import mx.com.switz.dao.AlumnoDao;
import mx.com.switz.dto.Alumno;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;

import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;

import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestParam;

import sun.java2d.pipe.SpanShapeRenderer;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;

/**
 *
 * @author chus
 */
@Repository
public class AlumnoDaoImpl extends JdbcDaoSupport implements AlumnoDao {

    private SimpleJdbcInsert simpleJdbcInsert;
    
    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;

    @Autowired
    public AlumnoDaoImpl(DataSource dataSource) {

        // se instancia plantilla con la inyeccion del datasource
    
    
        setDataSource(dataSource);
        this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(
                dataSource);
        simpleJdbcInsert = new SimpleJdbcInsert(getJdbcTemplate().getDataSource()).withTableName("Alumno");


    }

    public void insertAlumno(Alumno alumno) {
        SqlParameterSource parameters = new BeanPropertySqlParameterSource(alumno);
        simpleJdbcInsert.execute(parameters);
    }

    public List selectAlumnoByNombre(Alumno alumno) {        
        
        
        String query = "SELECT * FROM  Alumno WHERE nombre = :nombre" ;
        SqlParameterSource parameterSource = new BeanPropertySqlParameterSource(alumno);
        return  namedParameterJdbcTemplate.query(query, parameterSource,ParameterizedBeanPropertyRowMapper.newInstance(Alumno.class));

            
    }

  
}
